from tortoise.contrib.fastapi import register_tortoise
from tortoise import Tortoise

TORTOISE_ORM_CONFIG = {
    "connections": {
        "default": "mysql://root:123456@localhost:3306/test?charset=utf8mb4"
    },
    "apps": {
        "models": {
            "models": ["database.mysql", "aerich.models"],
            "default_connection": "default",
        }
    },
}

async def init_db():
    await Tortoise.init(config=TORTOISE_ORM_CONFIG)
    await Tortoise.generate_schemas(safe=True)

async def close_db():
    await Tortoise.close_connections()